home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kiconloaderdialog.h.z / kiconloaderdialog.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  6.3 KB  |  216 lines

  1. // -*- C++ -*-
  2.  
  3. //
  4. //  kiconloaderdialog
  5. //
  6. //  Copyright (C) 1997 Christoph Neerfeld
  7. //  email:  Christoph.Neerfeld@home.ivm.de or chris@kde.org
  8. //
  9. //  This program is free software; you can redistribute it and/or modify
  10. //  it under the terms of the GNU Library General Public License as published by
  11. //  the Free Software Foundation; either version 2 of the License, or
  12. //  (at your option) any later version.
  13. //
  14. //  This program is distributed in the hope that it will be useful,
  15. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. //  GNU Library General Public License for more details.
  18. //
  19. //  You should have received a copy of the GNU Library General Public License
  20. //  along with this program; if not, write to the Free Software
  21. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. //
  23.  
  24. // CHANGES
  25. // Torben, added KIconLoaderButton
  26.  
  27. #ifndef KICONLOADERDIALOG_H
  28. #define KICONLOADERDIALOG_H
  29.  
  30. #include <qapp.h>
  31. #include <qlist.h>
  32. #include <qpixmap.h>
  33. #include <qstrlist.h>
  34. #include <qstring.h>
  35. #include <qtablevw.h>
  36. #include <qdialog.h>
  37. #include <qlabel.h>
  38. #include <qlined.h>
  39. #include <qpushbt.h>
  40. #include <qcombo.h>
  41. #include <qtimer.h>
  42.  
  43. #include <kapp.h>
  44. #include <kiconloader.h>
  45.  
  46. /**
  47. * Internal display class for @ref KIconLoaderDialog
  48. * @short Internal display class for KIconLoaderDialog
  49. * @version $Id: kiconloaderdialog.h,v 1.9 1998/05/17 10:21:38 neerfeld Exp $
  50. * @author Christoph.Neerfeld@bonn.netsurf.de
  51. */
  52. class KIconLoaderCanvas : public QTableView
  53. {
  54.   Q_OBJECT
  55. public:
  56.   KIconLoaderCanvas (QWidget *parent=0, const char *name=0);
  57.   ~KIconLoaderCanvas ();
  58.  
  59.   void loadDir(QString dirname, QString filter);
  60.   QString getCurrent() { if(name_list.isEmpty()) return ""; return name_list.at(sel_id); }
  61.  
  62. signals:
  63.   void nameChanged( const char * );
  64.   void doubleClicked();
  65.  
  66. protected slots:
  67.   void process();
  68.  
  69. protected:
  70.   virtual void resizeEvent( QResizeEvent *e );
  71.  
  72.   void paintCell( QPainter *p, int r, int c );
  73.   void enterEvent( QEvent * ) { setMouseTracking(TRUE); }
  74.   void leaveEvent( QEvent * ) { setMouseTracking(FALSE); }
  75.   void mouseMoveEvent( QMouseEvent *e );
  76.   void mousePressEvent( QMouseEvent *e );
  77.   void mouseDoubleClickEvent( QMouseEvent *e );
  78.  
  79.   int            sel_id;
  80.   int            max_width;
  81.   int            max_height;
  82.   int            curr_indx;
  83.   QList<QPixmap> pixmap_list;
  84.   QStrList       file_list;
  85.   QStrList       name_list;
  86.   QTimer         *timer;
  87.   QString        dir_name;
  88. };
  89.  
  90. /** 
  91. * Dialog for interactive selection of icons.
  92. *
  93. * KIconLoaderDialog is a derived class from QDialog.
  94. * It provides one function selectIcon() which displays a dialog.
  95. * This dialog lets you select the icons within the IconPath by image.
  96. */
  97. class KIconLoaderDialog : public QDialog
  98. {
  99.   Q_OBJECT
  100. public:
  101.   /// Constructor
  102.   /**
  103.      The KIconLoaderDialog is a modal dialog; i.e. it has its own eventloop
  104.      and the normal program will stop after a call to selectIcon() until
  105.      selectIcon() returns.
  106.      This constructor creates a KIconLoaderDialog that will call
  107.      KApplication::getKApplication()->getIconLoader() to load any icons.
  108.      Note that it will not use this KIconLoader to display the icons, but
  109.      the QPixmap that it returns will be know to this KIconLoader.
  110.      KIconLoaderDialog caches all icons it has loaded as long as they are in the
  111.      same directory between two calls to selectIcon(). So it is a good idea to
  112.      delete the KIconLoaderDialog when it is not needed anymore.
  113.   */
  114.   KIconLoaderDialog ( QWidget *parent=0, const char *name=0 );
  115.  
  116.   /**
  117.      If you want to use another KIconLoader you can create the KIconLoaderDialog
  118.      with this constructor which accepts a pointer to a KIconLoader.
  119.      Make sure that this pointer is valid.
  120.   */
  121.   KIconLoaderDialog ( KIconLoader *loader, QWidget *parent=0, const char *name=0 );
  122.  
  123.   /// Destructor
  124.   ~KIconLoaderDialog ();
  125.  
  126.   /// Select an icon from a modal choose dialog
  127.   /**
  128.      This function pops up a modal dialog and lets you select an icon by its
  129.      picture not name. The function returns a QPixmap object and the icons 
  130.      name in 'name'
  131.      if the user has selected an icon, or null if the user has pressed the 
  132.      cancel button. So check the result before taking any action.
  133.      The argument filter specifies a filter for the names of the icons to 
  134.      display. For example "*" displays all icons and "mini*" displays only 
  135.      those icons which names start with 'mini'.
  136.   */
  137.   QPixmap selectIcon( QString &name, const QString &filter);
  138.   void setDir( const QStrList *l ) { cb_dirs->clear(); cb_dirs->insertStrList(l); }
  139.   int exec(QString filter);
  140.  
  141. protected slots:
  142.   void filterChanged();
  143.   void dirChanged(const char *);
  144.   
  145. protected:
  146.   void init();
  147.   virtual void resizeEvent( QResizeEvent *e );
  148.  
  149.   KIconLoaderCanvas *canvas;
  150.   QLabel            *l_name;
  151.   QLineEdit         *i_filter;
  152.   QLabel            *l_filter;
  153.   QPushButton       *ok;
  154.   QPushButton       *cancel;
  155.   QLabel            *text;
  156.   QComboBox         *cb_dirs;
  157.   KIconLoader       *icon_loader;
  158. };
  159.  
  160. /**
  161.  * This is a button that uses the @ref KIconLoaderDialog.
  162.  * It shows the currently selected icon. Pressing on
  163.  * the icon will open the dialog. If the icon changes, a
  164.  * signal is emitted and the buttons pixmap becomes updated.
  165.  *
  166.  * HACK
  167.  * Since I did not want to break binary compatibility, it does
  168.  * NOT use the same search path as the dialog. This IS a bug.
  169.  */
  170. class KIconLoaderButton : public QPushButton
  171. {
  172.     Q_OBJECT
  173. public:
  174.     /**
  175.      * Creates a new button.
  176.      */
  177.     KIconLoaderButton( QWidget *_widget );
  178.     KIconLoaderButton( KIconLoader *_icon_loader, QWidget *_widget );
  179.     ~KIconLoaderButton();
  180.     
  181.     /**
  182.      * Set the buttons icon. 
  183.      *
  184.      * @param _icon is a parameter as usually passed to @ref KIconLoader.
  185.      */
  186.     void setIcon( const char *_icon );
  187.     /**
  188.      * @return the name of the icon without path.
  189.      */
  190.     const char* icon() { return iconStr.data(); }
  191.     /**
  192.      * @return a reference to the icon loader dialog used.
  193.      */
  194.     KIconLoaderDialog* iconLoaderDialog() { return loaderDialog; }
  195.     
  196. public slots:
  197.     void slotChangeIcon();
  198.     
  199. signals:
  200.     /**
  201.      * Emitted if the icons has changed.
  202.      */
  203.     void iconChanged( const char *icon );
  204.     
  205. protected:
  206.     KIconLoaderDialog *loaderDialog;
  207.     QString iconStr;
  208.     KIconLoader *iconLoader;
  209. };
  210.  
  211.  
  212. #endif // KICONLOADERDIALOG_H
  213.  
  214.  
  215.  
  216.